﻿cbuffer cbPerObject
{
	float4x4 WorldViewProjection;	
	float4x4 WorldView;	
	float4x4 View;	
	float4x4 InverseProjection;
	float4x4 ViewToLightProjection;
	float4x4 ViewToLightView;
}

cbuffer cbGlobal
{
	int2 _size;
	float _minLum;
}

SamplerState ClampLumSampler
{
	Filter = MIN_MAG_POINT_MIP_LINEAR;
    AddressU = Clamp;
    AddressV = Clamp;
};

Texture2D _input;

struct App2VS
{
	float3 pos : POSITION;
	float3 col : COLOR;
	float3 normal : NORMAL;
};
struct VS2PS
{
	float4 pos : SV_Position;
};
struct PS2GPU
{
	float4 value : SV_Target0;
};

void vs(App2VS IN, out VS2PS OUT)
{
	OUT.pos = float4(IN.pos, 1); //pass through for quad/etc

}
void ps(VS2PS IN, out PS2GPU OUT)
{
	float2 uv = IN.pos / _size;
	
	float4 src = _input.Sample(ClampLumSampler, uv);
	float lum = dot(src.rgb, float3(0.3, 0.59, 0.11));
	[flatten]
	if(lum > _minLum)
	{
		OUT.value = src;
	}
	else
	{
		OUT.value = 0;
	}
}

technique10 Render
{
	pass P0
	{
		SetGeometryShader( 0 );
		SetVertexShader( CompileShader( vs_4_0, vs() ) );
		SetPixelShader( CompileShader( ps_4_0, ps() ) );
	}
}